﻿layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;


    form.on("submit(inCoin)", function (data) {
        //console.log(data);
        $.ajax({
            type: 'POST',
            url: '/InOutCash/AuditCustomInCoin',
            data: {
                Id: $("#Id").val(),
                Money: $("#Money").val(),
                RMBMoney: $("#RMBMoney").val()
            },
            dataType: "json",
            headers: {
                "X-CSRF-TOKEN-yilezhu": $("input[name='AntiforgeryKey_yilezhu']").val()
            },
            success: function (data) {//res为相应体,function为回调函数
                var index = layer.msg(data.ResultMsg, {
                    time: 2000 //20s后自动关闭
                }, function () {
                    parent.location.reload();
                    layer.close(index);
                });
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, { icon: 5 });
            }
        });
        return false;
    });

    //form.verify({
    //    alipay: function (value, item) { //value：表单的值、item：表单的DOM对象
    //        var val = parseFloat(value);
    //        if (!isNaN(val)) {
    //            if (val <= 0 || val > 6000) {
    //                return "单笔最高入金6000美元";
    //            }
    //        }
    //    }
    //});  

    $("#RMBMoney").keyup(function () {
        sumMoney($(this).val());
    });

    function sumMoney(value) {
        var rate = parseFloat($("#ExchangeRate").val());
        var money = parseFloat(value);
        var total = 0;
        if (!isNaN(rate) && !isNaN(money)) {
            var _m = money * 100;
            total = Math.round((_m - _m * 0.005) / rate) /100;
        }
        $("#Money").val(total);
    }

});

